home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / misc / RISCOS / gnpltst_sm < prev    next >
Text File  |  1995-10-16  |  5KB  |  257 lines

  1.  #
  2.  # Test 2-D plots
  3.  #
  4.  
  5.  printf (" Have you got a gnuplot-3.5 patched with multiplot and border? (y/n) (def. no) ");
  6.  ans = getline ("stdin");
  7.  
  8.  x = (0.25:4:.25)';
  9.  
  10.  //-----------------------------------------------------------------//
  11.  autoscale();
  12.  title ("Multiple Line Colors and Styles");
  13.  linestyle ("line");
  14.  nogrid();
  15.  xlabel ("X-axis Label");
  16.  ylabel ("Y-axis Label");
  17.  plot ( [x, x, 2*x, 3*x] );
  18.  pause ("Type RETURN to continue");
  19.  
  20.  title ("Multiple Point Colors and Styles");
  21.  linestyle ("point");
  22.  nogrid();
  23.  plot ( [x, x, 2*x, 3*x] );
  24.  pause ("Type RETURN to continue");
  25.  
  26.  title ("Multiple Line-Point Colors and Styles");
  27.  linestyle ("linespoint");
  28.  grid();
  29.  plot ( [x, x, 2*x, 3*x] );
  30.  pause ("Type RETURN to continue");
  31.  
  32.  title ("Multiple Line-Point Colors and Styles");
  33.  linestyle ("lines");
  34.  nogrid();
  35.  plot ( [x, x] );
  36.  linestyle ("point");
  37.  replot ( [x, 2*x] );
  38.  linestyle ("linespoint");
  39.  replot ( [x, 3*x] );
  40.  pause ("Type RETURN to continue");
  41.  
  42.  nogrid();
  43.  //-----------------------------------------------------------------//
  44.  # Show off axis types
  45.  title("Linear Axes");
  46.  grid();
  47.  nolog();
  48.  plot ([x,exp(-x*0.5)]);
  49.  pause ("Type RETURN to continue");
  50.  
  51.  title("Log X - Axis");
  52.  grid();
  53.  semilogx();
  54.  plot ([x,exp(-x*0.5)]);
  55.  pause ("Type RETURN to continue");
  56.  
  57.  title("Log Y - Axis");
  58.  grid();
  59.  semilogy();
  60.  plot ([x,exp(-x*0.5)]);
  61.  pause ("Type RETURN to continue");
  62.  
  63.  title("Log  Axes");
  64.  loglog();
  65.  grid();
  66.  plot ([x,exp(-x*0.5)]);
  67.  pause ("Type RETURN to continue");
  68.  
  69.  nolog();
  70.  nogrid();
  71.  
  72.  //-----------------------------------------------------------------//
  73.  pause ("Type RETURN to continue");
  74.  autoscale();
  75.  
  76.  //-----------------------------------------------------------------//
  77.  # Make 3D data
  78.  
  79.  # Sombrero
  80.  
  81.  NX = 20;
  82.  NY = 20;
  83.  xx = zeros (1, NX);
  84.  yy = zeros (1, NY);
  85.  for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  86.  for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  87.  
  88.  zz = zeros (NX, NY);
  89.  
  90.  for (i in 1:NX)
  91.  {
  92.      for (j in 1:NY)
  93.      {
  94.      r = sqrt (xx[i]^2 + yy[j]^2);
  95.      zz[i;j] = exp (-r * r) * cos (2*pi*r);
  96.      }
  97.  }
  98.  
  99.  # Now create some plots
  100.  
  101.  title("3-D Plot, Sombrero");
  102.  grid();
  103.  splot(xx,yy,zz);
  104.  pause ("Type RETURN to continue");
  105.  
  106.  
  107.  # Sin - Cos surface
  108.  
  109.  x1 = -3:3:.2;
  110.  y1 = -3:3:.2;
  111.  z1 = zeros (x1.n, y1.n);
  112.  
  113.  for (i in 1:x1.n)
  114.  {
  115.      for(j in 1:y1.n)
  116.      {
  117.      z1[i;j] = sin(y1[j]) * cos(x1[i]);
  118.      }
  119.  }
  120.  
  121.  title("3-D Plot, Cos-Sine Surface");
  122.  nogrid();
  123.  splot(x1,y1,z1);
  124.  pause ("Type RETURN to continue");
  125.  
  126.  
  127.  # Slanted plane
  128.  
  129.  x2 = 1:10;
  130.  y2 = 1:10;
  131.  z2 = zeros (x2.n, y2.n);
  132.  for (i in 1:x2.n) { z2[i;] = i*ones(1,y2.n); }
  133.  
  134.  title("3-D Plot, Plane");
  135.  splot(x2,y2,z2);
  136.  pause ("Type RETURN to continue");
  137.  
  138.  
  139.  # Two Slanted planes
  140.  z3 = -2*z2;
  141.  title("3-D Plot, 2 - Planes");
  142.  splot(x2,y2,[z2',z3]);
  143.  pause ("Type RETURN to continue");
  144.  
  145.  
  146.  
  147.  //-----------------------------------------------------------------//
  148.  
  149.  #
  150.  # Simple contour plotting demonstration
  151.  #
  152.  
  153.  NX = 20;
  154.  NY = 20;
  155.  xx = zeros (1, NX);
  156.  yy = zeros (1, NY);
  157.  for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  158.  for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  159.  
  160.  zz = zeros (NX, NY);
  161.  
  162.  for (i in 1:NX)
  163.  {
  164.      for (j in 1:NY)
  165.      {
  166.      r = sqrt (xx[i]^2 + yy[j]^2);
  167.      zz[i;j] = exp (-r * r) * cos (2*pi*r);
  168.      }
  169.  }
  170.  
  171.  # Sin - Cos surface
  172.  
  173.  x1 = -3:3:.2;
  174.  y1 = -3:3:.2;
  175.  z1 = zeros (x1.n, y1.n);
  176.  
  177.  for (i in 1:x1.n)
  178.  {
  179.      for(j in 1:y1.n)
  180.      {
  181.      z1[i;j] = sin(y1[j]) * cos(x1[i]);
  182.      }
  183.  }
  184.  
  185.  # Now create some plots
  186.  
  187.  xlabel("X-Axis");
  188.  ylabel("Y-Axis");
  189.  title ("Contour Demonstration");
  190.  cont(xx,yy,zz);
  191.  pause ("Type RETURN to continue");
  192.  
  193.  xlabel("X-Axis");
  194.  ylabel("Y-Axis");
  195.  title ("Contour Demonstration");
  196.  cont (x1,y1,z1);
  197.  pause ("Type RETURN to continue");
  198.  
  199.  
  200.  //-----------------------------------------------------------------//
  201.  
  202.  #
  203.  # demonstrate replot, multiplot and plotyy.
  204.  #
  205.  
  206.  x=0:10:0.1;
  207.  m1=[x',sin(x)'];
  208.  m2=[x',(cos(x)+1)'];
  209.  
  210.  key();
  211.  title("a sin(x).");
  212.  plot(m1,["sin(x)"]);
  213.  pause("Type RETURN to continue");
  214.  
  215.  
  216.  title("cos(x)+1 added with a replot(data) command.");
  217.  replot(m2,["cos(x)+1"]);
  218.  pause("Type RETURN to continue");
  219.  
  220.  if (ans.[1] == "y" || ans.[1] == "Y") {
  221.      title("Plot with txo y-axes");
  222.      plotyy();
  223.      key();
  224.      linestyle("lines");
  225.      ylabel("sin(x)");
  226.      plot(m1,["sin(x)"]);
  227.      ylabel("cos(x)+1");
  228.      plot(m2,["cos(x)+1"]);
  229.      pause("Type RETURN to continue");
  230.      
  231.      nokey();
  232.      ylabel ("Y-axis");
  233.      multiplot(2,2);
  234.      linestyle("lines");
  235.      title("Sombrero");
  236.      splot(xx,yy,zz);
  237.      x = (0.25:4:.25)';
  238.      y = (0.5:6:.2)';
  239.      title("Different Scales");
  240.      grid();
  241.      plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
  242.      nogrid();
  243.      plotyy();
  244.      title("Plot with txo y-axes");
  245.      ylabel("sin(x)");
  246.      plot(m1);
  247.      ylabel("cos(x)+1");
  248.      plot(m2);
  249.      xlabel("");
  250.      ylabel("");
  251.      title("Contour plot");
  252.      cont(xx,yy,zz);
  253.      pause("Type RETURN to continue");
  254.      
  255.  }
  256.  pclose(0);
  257.